package com.fang.springcrud.service;

import com.fang.springcrud.dao.UserDao;
import com.fang.springcrud.entity.UserEntity;
import com.fang.springcrud.resp.ResponseBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

    @Autowired
    public UserDao userDao;

    public ResponseBean.Page userList(int page, int limit, String key) {

        ResponseBean.Page page1 = new ResponseBean.Page();
        //查询列表数据
        List<UserEntity> userEntities = userDao.queryList(page, limit, key);
        //查询数量
        int count = userDao.count(key);
        page1.setTotalCount(count);
        page1.setList(userEntities);
        return page1;
    }

    public UserEntity selectForId(String id) {
        return userDao.selectForId(id);
    }

    public void updateEntity(UserEntity entity) {
        userDao.updateEntity(entity);
    }

    public void deleteForIds(int[] ids) {
       userDao.deleteForIds(ids);
    }

    public void save(UserEntity entity) {
        userDao.save(entity);
    }
}
